home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Add-On
/
Workbench Add-On - Volume 1.iso
/
Dev
/
Oberon
/
source
/
ProgInOberon
/
RandomNumbers.mod
< prev
Wrap
Text File
|
1995-07-02
|
1KB
|
61 lines
(*************************************************************************
$RCSfile: RandomNumbers.mod $
Description: Random number generator from "Programming In Oberon"
Created by: fjc (Frank Copeland)
$Revision: 1.10 $
$Author: fjc $
$Date: 1995/06/04 23:23:57 $
Copyright © 1990-1993, ETH Zuerich
Copyright © 1994, Frank Copeland.
This file is part of the Oberon-A Library.
See Oberon-A.doc for conditions of use and distribution.
*************************************************************************)
MODULE RandomNumbers;
IMPORT d := Dos;
VAR z : LONGINT;
(*------------------------------------*)
PROCEDURE Uniform * () : REAL;
CONST a = 16807; m = 2147483647; q = m DIV a; r = m MOD a;
VAR gamma : LONGINT;
BEGIN (* Uniform *)
gamma := a * (z MOD q) - r * (z DIV q);
IF gamma > 0 THEN z := gamma
ELSE z := gamma + m
END;
RETURN z * (1.0 / m)
END Uniform;
(*------------------------------------*)
PROCEDURE InitSeed * (seed : LONGINT);
BEGIN (* InitSeed *)
z := seed
END InitSeed;
(*------------------------------------*)
PROCEDURE TimeSeed * ();
VAR ds : d.Date; x : REAL;
BEGIN (* TimeSeed *)
d.DateStamp (ds);
z := (ds.minute * (60 * d.ticksPerSecond)) + ds.tick;
x := Uniform()
END TimeSeed;
BEGIN
z := 314159
END RandomNumbers.